<?php

/* * *********************************************************** */
/* * ********************** Classe PermissaoDao ********************* */
/* * ************ Desenvolvido por Antônio Ezequiel ************** */
/* * *********************************************************** */

class PermissaoDao extends Permissao {

    public function listarPermissoes() {

        global $configurator;

        parent::conectarBD();

        $queri = parent::query("select per_codigo as codigo, per_permissao as permissao from tbl_permissao");

        if ($queri) {
            $dados = parent::fetch_rows($queri);
            parent::desconectarBD();
            return $dados;
        } else {
            parent::desconectarBD();
            return false;
        }
    }

     public function listarPermissoesUsuario($codigo) {

        global $configurator;

        parent::conectarBD();
        $queri = parent::query("select u.per_codigo as codigo, per_permissao as permissao from tbl_usu_permissao u inner join tbl_permissao p on
                                u.per_codigo = p.per_codigo where usu_codigo = '$codigo'");

        if ($queri) {
            $dados = parent::fetch_rows($queri);
            parent::desconectarBD();
            return $dados;
        } else {
            parent::desconectarBD();
            return false;
        }
    }

    public function adicionarPermissaoUsuario() {

        global $configurator;

        parent::conectarBD();
        
        $queri = parent::query("insert into tbl_usu_permissao (usu_codigo, per_codigo) values ('$this->usu_codigo','$this->per_codigo')");

        if ($queri) {
            $id = parent::get_insert_id();
            parent::desconectarBD();
            return $id;
        } else {
            parent::desconectarBD();
            return false;
        }
    }

    public function deletarPermissaoUsuario($codigo) {

        global $configurator;

        parent::conectarBD();

        $queri = parent::query("delete from tbl_usu_permissao where usu_codigo = '$codigo'");

        if ($queri) {
            parent::desconectarBD();
            return true;
        } else {
            parent::desconectarBD();
            return false;
        }
    }

}

?>
